package def;

import Lights.*;
import PysicalSurfacesObjects.*;

import java.util.ArrayList;
import java.util.List;

import def.Parser.ParseException;

import Basics.RGBColor;
import Basics.myVector;


public class Scene {

	private List<Light> lights;
	private List<Entity> entities;
	private Camera camera;
	private RGBColor background_color;
	private String background_texture;
	private RGBColor ambient_light;
	private int super_sample_width;
	private int use_acceleration;
	private int width ;
	private int height;
	
	public List<Light> getLights()
	{
		return lights;
	}
	
	public List<Entity> getEntities()
	{
		return entities;
	}
	
	public Camera getCamera()
	{
		return camera;
	}
	
	public void setCamera(Camera camera)
	{
		this.camera =camera;		
	}
	
	public void addEntity(Entity object)
	{		
		entities.add((Entity)object);
	}
	
	public void addLight(Light light)
	{
		lights.add(light);
	}
	
	public void setCanvasSize(int height, int width)
	{
		this.height = height;
		this.width = width;
	}

    public boolean setParameter(String name, String[] args)  {
        if (name.equals("background-col")) {
            if (args.length != 3) {
                return false;
            }
            
            background_color = new RGBColor(ourParser.parseArrayOfDoubles(args));
            return true;
        } else if (name.equals("background-tex")) {
            if (args.length != 1) {
                return false;
            }
            background_texture = args[0];
            return true;
        } else if (name.equals("super-samp-width")) {
            if (args.length != 1) {
                return false;
            }
            super_sample_width = Integer.parseInt(args[0]);
            return true;
        } else if (name.equals("ambient-light")) {
            if (args.length != 3) {
                return false;
            }
            ambient_light = new RGBColor(ourParser.parseArrayOfDoubles(args));
            return true;
        }

        // We didn't find any parameter
        return false;
    }
	
    public RGBColor getColor(int x,int y)
    {
    	 Ray ray = new Ray(camera.getEye(),new myVector(1,1,1));
    	 Intersection intersect = getMinimalIntersection(ray);
         if (intersect == null) {
             return getBackgroundColor(x, y);
         }
    	return new RGBColor();
    }

	private Intersection getMinimalIntersection(Ray ray) {
	 	List<Intersection> intersections = new ArrayList<Intersection>();
    	for (Entity entity : entities) {
			Intersection intersection = entity.Intersect(ray);
			if(intersection != null)
				intersections.add(intersection);
		}
		return null;
	}
}
